package com.songtech.dictionary.controller;


import com.songtech.auth.user.model.User;
import com.songtech.base.common.BaseConstant;
import com.songtech.base.common.JsonResult;
import com.songtech.common.dictionary.bean.SysDictionaryGroup;
import com.songtech.common.dictionary.bean.ThreeSelect;
import com.songtech.common.dictionary.service.SysDictionaryGroupService;
import com.songtech.shiro.annotation.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: RENTIE
 * Date: 2018-06-19 10:12
 */
@RestController
@RequestMapping("/dictionarygroup")
public class SysDictionaryGroupController {

    private final Logger logger = LoggerFactory.getLogger(SysDictionaryGroupController.class);

    @Autowired
    private SysDictionaryGroupService sysDictionaryGroupService;


    @RequestMapping(value = "/vender",method = RequestMethod.GET)
    public JsonResult selectVenderByCode(@UserInfo User user){
        List<ThreeSelect> list=null;
        try {
            List<SysDictionaryGroup> groups = null;
            if("admin".equals(user.getLoginName())){
                groups =sysDictionaryGroupService.selectVenderByCode(BaseConstant.DIC_VENDER);
            }else{
                groups= sysDictionaryGroupService.selectVenderByCompanyId(user.getCompanyId());

            }
            list=sysDictionaryGroupService.selectThreeSelect(groups);
        }catch (Exception e) {
            logger.error("查询厂家异常信息:"+e.getMessage(),e);
            return new JsonResult(list, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list, BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS);
    }
}
